
export const convertDateTimeArray = (dateTime) => {
	try{
		let date = new Date(getDateOrDefault(dateTime[0]), getDateOrDefault(dateTime[1]-1), getDateOrDefault(dateTime[2]), getDateOrDefault(dateTime[3]), getDateOrDefault(dateTime[4]), getDateOrDefault(dateTime[5]))
		return date
	} catch(error){
		return new Date(1970,0,1,0,0,0)
	}
	
}

const getDateOrDefault = (num) =>{
	return num ? num : 0
}

export const fillDateItem = (num) => {
	return (num) < 10 ? `0${num}` : (num).toString()
}

export const getDateTimeString = (dateTime) => {
	let date = convertDateTimeArray(dateTime)
	return convertDateTimeArrayToString(date)
}

export const convertDateTimeArrayToString = (date) => {
	let monthStr = fillDateItem(date.getMonth()+1)
	let dayStr = fillDateItem(date.getDate())
	let hourStr = fillDateItem(date.getHours())
	let minStr = fillDateItem(date.getMinutes())
	let secStr = fillDateItem(date.getSeconds())
	return `${date.getFullYear()}-${monthStr}-${dayStr} ${hourStr}:${minStr}:${secStr}`
}